package org.example.kunkun_filter.service;

import org.example.kunkun_filter.dao.LoginResponse;
import org.example.kunkun_filter.mapper.LoginMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginService {

    @Autowired
    private LoginMapper loginMapper;

    public LoginResponse.User registerUser(LoginResponse.User user) {
        // 检查用户是否已存在
        LoginResponse.User existingUser = loginMapper.getUserByOpenid(user.getOpenid());
        if (existingUser != null) {
            // 用户已存在，返回现有用户信息
            return existingUser;
        } else {
            // 用户不存在，注册新用户
            loginMapper.registerUser(user);
            return user;
        }
    }
}
